package com.ruoyi.syrw.common;

import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@RequiredArgsConstructor
public class LineFunction {

    private double k;

    private double b;

    public LineFunction(double k, double b) {
        if (Double.isNaN(k)) {
            k = 0;
        }
        if (Double.isNaN(b)) {
            b = 0;
        }
        this.k = k;
        this.b = b;
    }

    public double getY(double x) {
        return value(x, k, b);
    }

    private double value(double x, double k, double b) {
        return k * x + b;
    }

    public double getX(double y) {
        return (y - b) / k;
    }
}
